package cn.dankal.flyaudio.contract;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import cn.dankal.flyaudio.model.FlyUser;
import cn.jmessage.support.google.gson.Gson;

import static android.content.Context.MODE_PRIVATE;

public class LoginContractHelper {

    public static final String LOGIN_SUCCESS = "cn.dankal.flyaudio.LOGIN_SUCCESS";

    /**
     * 发送登录成功广播
     */
    public static void sendLoginBoardCast(Context context) {
        LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
        Intent intent = new Intent(LOGIN_SUCCESS);
        localBroadcastManager.sendBroadcast(intent);
    }

    public static void saveLoginUserInfo(Context context, FlyUser userInfoJson) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("sp_fly", MODE_PRIVATE);
        sharedPreferences
                .edit()
                .putString("fly_user", new Gson().toJson(userInfoJson))
                .apply();
    }
}
